package main

import (
	"fmt"
	"demserver/src/elevation"
)

func main() {
	// Test loading GeoTIFF with TFW file
	filename := "./demdata/ClipResult.tif"
	
	fmt.Printf("Loading GeoTIFF file: %s\n", filename)
	geoTiff, err := elevation.LoadGeoTIFF(filename)
	if err != nil {
		fmt.Printf("Failed to load GeoTIFF: %v\n", err)
		return
	}
	fmt.Println("GeoTIFF loaded successfully")
	fmt.Printf("Image dimensions: %dx%d\n", geoTiff.Width, geoTiff.Height)
	fmt.Printf("Geotransform: %+v\n", geoTiff.GeoTransform)
	
	// Test coordinate conversion with your coordinates
	lat := 31.029596331678416
	lon := 103.55108474360813
	x, y, err := geoTiff.LatLonToPixel(lat, lon)
	if err != nil {
		fmt.Printf("Failed to convert coordinates (%f, %f): %v\n", lat, lon, err)
		return
	}
	fmt.Printf("Pixel coordinates for (%f, %f): (%f, %f)\n", lat, lon, x, y)
	
	// Check if coordinates are within bounds
	if x < 0 || y < 0 || x >= float64(geoTiff.Width) || y >= float64(geoTiff.Height) {
		fmt.Printf("Coordinates out of bounds. Image size: %dx%d\n", geoTiff.Width, geoTiff.Height)
	} else {
		fmt.Printf("Coordinates are within bounds\n")
	}
}
